﻿using ShoppingCar.prefecture;
using ShoppingCar.Prefectures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ShoppingCar
{
    public class PrefecturesAppService : ApplicationService, IPrefecturesServic
    {
        private readonly IRepository<Prefecture, int> _Prefecture;

        public PrefecturesAppService(IRepository<Prefecture, int> prefectures)
        {

            _Prefecture = prefectures;
        }
        //添加
        public int CreatePrefectures(CreateUpdatePrefecturesDto dto)
        {
            var add = new Prefecture()
            {
                PrefectureName = dto.PrefectureName,
                Prefecturedescribe = dto.Prefecturedescribe,
                PrefectureOrder = dto.PrefectureOrder,
                Prefecturestate = dto.Prefecturestate
            };
            _Prefecture.InsertAsync(add);
            return 10;
        }
        //删除
        public int DeletePrefectures(int id)
        {
            _Prefecture.DeleteAsync(id);
            return 10;
        }
        //反填
        public PrefecturesDto Fantian(int id)
        {
            Prefecture bottom = _Prefecture.Where(s => s.Id.Equals(id)).FirstOrDefault();
            return ObjectMapper.Map<Prefecture, PrefecturesDto>(bottom);
        }
        //显示
        public List<PrefecturesListDto> GetButtomLists()
        {
            var get = from a in _Prefecture
                      select new PrefecturesListDto
                      {
                          Id = a.Id,
                          PrefectureName = a.PrefectureName,
                          Prefecturedescribe = a.Prefecturedescribe,
                          PrefectureOrder = a.PrefectureOrder,
                          Prefecturestate = a.Prefecturestate
                      };
            var list = get.ToList();
            return list;
        }
        //修改
        public int UpdatePrefectures(int id, CreateUpdatePrefecturesDto dto)
        {
            Prefecture headss = _Prefecture.FirstOrDefault(s => s.Id.Equals(id));
            headss.PrefectureName = dto.PrefectureName;
            headss.Prefecturedescribe = dto.Prefecturedescribe;
            headss.PrefectureOrder = dto.PrefectureOrder;
            headss.Prefecturestate = dto.Prefecturestate;
            _Prefecture.UpdateAsync(headss);
            return 10;
        }
        //修改状态
        public PrefecturesDto UpdateState(int id)
        {
            Prefecture bottom1 = _Prefecture.FirstOrDefault(s => s.Id.Equals(id));
            if (bottom1.Prefecturestate == 1)
            {
                bottom1.Prefecturestate = 0;
            }
            else
            {
                bottom1.Prefecturestate = 1;
            }
            return ObjectMapper.Map<Prefecture, PrefecturesDto>(bottom1);
        }
    }
}
